package com.sky.mapper;

import com.sky.entity.Top;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ReportMapper {

    //查询条件状态已完成的订单金额
    @Select("select sum(amount) from orders where status=5 and order_time > #{begin} and order_time < #{end}")
    Double getTurnoverByTime(LocalDateTime begin, LocalDateTime end);

    //查询某一天的新增用户数量
    @Select("select count(id) from user where create_time > #{begin} and create_time < #{end}")
    Integer getUserByTime(LocalDateTime begin, LocalDateTime end);

    //查询某一天的用户使用量
    @Select("select count(DISTINCT user_id) from orders where order_time>#{begin} and order_time < #{end}")
    Integer getAllUser(LocalDateTime begin, LocalDateTime end);
    
    //订单总数
    @Select("select count(id) from orders")
    Integer getTotalOrderCount();

    //有效订单数
    @Select("select count(status) from orders where status = 5")
    Integer getValidOrderCount();
    
    //每日订单数量
    @Select("select count(id) from orders where order_time > #{beginTime} and order_time < #{endTime}")
    Integer getOrderCount(LocalDateTime beginTime, LocalDateTime endTime);

    //每日有效订单数量
    @Select("select count(id) from orders where order_time > #{beginTime} and order_time < #{endTime} and status = 5")
    Integer getValidOrder(LocalDateTime beginTime, LocalDateTime endTime);

    //获取销售排行
    @Select("select name,sum(order_detail.number) as number FROM order_detail inner join sky_take_out.orders on order_detail.order_id = orders.id where orders.order_time>#{beginTime} and orders.order_time < #{endTime} and orders.status = 5 GROUP BY name ORDER BY  number DESC")
    List<Top> getTop(LocalDateTime beginTime, LocalDateTime endTime);
}
